package com.wingbow.ticket.netty;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.impl.FrameType;
import io.vertx.core.http.impl.ws.WebSocketFrameImpl;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class WebsocketClientVerticle extends AbstractVerticle {

    @Override
    public void start() throws Exception {
        HttpClient client = vertx.createHttpClient();
        client.websocket(80, "192.168.1.24", "/ticket/host/123", websocket -> {
            websocket.textMessageHandler(str -> {
                log.info("收到消息：{}", str);
                WebSocketFrameImpl closeWebSocketFrame = new WebSocketFrameImpl(FrameType.CLOSE);
                closeWebSocketFrame.setTextData("close close");
                websocket.writeFrame(closeWebSocketFrame);
                websocket.close();
            });
        });
    }
}
